<?php
/**
 * Script for fetching and preparing the information which will be displayed
 * in a downloaded text-file. Calls downloadFile.php.
 */

// Start the session handling system
session_start ();

// Connect to the database
require_once ("../../../db.php");

// Only allow this when the person is logged in.
if (!isset($_SESSION['uid']))
    die('You are not logged in');

$sql =
'SELECT p.*, e.companyname
FROM projects p, externalusers e
WHERE p.id='.$_GET['pid'].' AND p.owner = e.id';

$sth = $db->prepare($sql);
$sth->execute();
$row = $sth->fetch();

// Make the proper display of the information:
$filecontent="
    Title: ".$row["title"]."\n
    Alternative title: ".$row['altTitle']."\n
    Owner: ".$row['owner']."\n
    Starttidspunkt: ".$row['date']."\n
    1. Advisor: ".$row['advisor1']."\n
    2. Advisor: ".$row['advisor2']."\n
    Status: ".$row['status']."\n
    Description: ".$row['description']."\n
    Comments: ".$row['collegiumComments']."\n
";
?>

<!--
 Create a hidden form for containing the information that will be downloaded:
-->
<form name="hiddenDownloadForm" id="hm" method="post" action="downloadFile.php">
    <textarea id="fileContent" name="fileContent" style="visibility: hidden">
        <?php echo $filecontent; ?></textarea>
</form>

<!-- Automatically send the information to downloadFile.php -->
<script type="text/javascript">
    document.forms['hiddenDownloadForm'].submit();
</script>

